﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;
using BusinessLayer.BLServerReference;
using System.Configuration;

namespace BusinessLayer
{
    class LocalBusinessLayerClient : IBL
    {
        private string _hash;
        private string Hash
        {
            get
            {
                return _hash;
            }
            set
            {
                _hash = value;
            }
        }
        private BLServerReference.IBLS blClient;
        public LocalBusinessLayerClient()
        {
            blClient = new BLServerReference.BLSClient("BasicHttpBinding_IBLS");
            _hash = ConfigurationManager.AppSettings["ServiceHash"] ?? "";
        }

        public ModelValidationReportOfUsersJEn804l LoginUser(string email, string password)
        {
            return blClient.LoginUser(email, password,Hash);
        }

        public Task<BLServerReference.User> LoginUserAsync(string email, string password)
        {
            throw new NotImplementedException();
        }

        public string CreateActivationHash(BLServerReference.User user)
        {
            return blClient.CreateActivationHash(user, Hash);
        }

        public Task<string> CreateActivationHashAsync(BLServerReference.User user)
        {
            throw new NotImplementedException();
        }

        public BLServerReference.User ValidateActivationHash(string hash, int userId)
        {
            return blClient.ValidateActivationHash(hash, userId, Hash);
        }

        public Task<BLServerReference.User> ValidateActivationHashAsync(string hash, int userId)
        {
            throw new NotImplementedException();
        }

        public ModelValidationReportOfUsersJEn804l CreateUser(BLServerReference.User user)
        {
            return blClient.CreateUser(user, Hash);
        }

        public Task<BLServerReference.User> CreateUserAsync(BLServerReference.User user)
        {
            throw new NotImplementedException();
        }

        public BLServerReference.User GetUserByID(int id)
        {
            return blClient.GetUserByID(id, Hash);
        }

        public Task<BLServerReference.User> GetUserByIDAsync(int id)
        {
            throw new NotImplementedException();
        }

        public BLServerReference.User GetUserByEmail(string email)
        {
            return blClient.GetUserByEmail(email, Hash);
        }

        public Task<BLServerReference.User> GetUserByEmailAsync(string email)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<Hall> GetAllHalls()
        {
            return blClient.GetAllHalls(Hash);
        }

        public Task<BLServerReference.Hall[]> GetAllHallsAsync()
        {
            throw new NotImplementedException();
        }

        public BLServerReference.Hall GetHallById(int id)
        {
            return blClient.GetHallById(id, Hash);
        }

        public Task<BLServerReference.Hall> GetHallByIdAsync(int id)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<BLServerReference.City> GetCitiesByKeyWord(string keyWord)
        {
            return blClient.GetCitiesByKeyWord(keyWord, Hash);
        }

        public Task<BLServerReference.City[]> GetCitiesByKeyWordAsync(string keyWord)
        {
            throw new NotImplementedException();
        }

        public BLServerReference.City GetCityByName(string name)
        {
            return blClient.GetCityByName(name, Hash);
        }

        public Task<BLServerReference.City> GetCityByNameAsync(string name)
        {
            throw new NotImplementedException();
        }

        public BLServerReference.City GetCityByID(int id)
        {
            return blClient.GetCityByID(id, Hash);
        }

        public Task<BLServerReference.City> GetCityByIDAsync(int id)
        {
            throw new NotImplementedException();
        }

        public ModelValidationReportOfEventsJEn804l CreateEvent(BLServerReference.Event aEvent)
        {
            return blClient.CreateEvent(aEvent, Hash);
        }

        public Task<BLServerReference.Event> CreateEventAsync(BLServerReference.Event aEvent)
        {
            throw new NotImplementedException();
        }

        public BLServerReference.Event GetEventById(int id)
        {
            return blClient.GetEventById(id, Hash);
        }

        public Task<BLServerReference.Event> GetEventByIdAsync(int id)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<BLServerReference.Event> GetUsersEvents(BLServerReference.User user)
        {
            return blClient.GetUsersEvents(user, Hash);
        }

        public Task<BLServerReference.Event[]> GetUsersEventsAsync(BLServerReference.User user)
        {
            throw new NotImplementedException();
        }

        public BLServerReference.EventReport GetEventReport(BLServerReference.Event aEvent)
        {
            return blClient.GetEventReport(aEvent, Hash);
        }

        public Task<BLServerReference.EventReport> GetEventReportAsync(BLServerReference.Event aEvent)
        {
            throw new NotImplementedException();
        }

        public void DeleteEvent(BLServerReference.Event aEvent)
        {
            blClient.DeleteEvent(aEvent, Hash);
        }

        public Task DeleteEventAsync(BLServerReference.Event aEvent)
        {
            throw new NotImplementedException();
        }

        public ModelValidationReportOfEventsJEn804l UpdateEvent(BLServerReference.Event _event)
        {
            return blClient.UpdateEvent(_event, Hash);
        }

        public Task<BLServerReference.Event> UpdateEventAsync(BLServerReference.Event _event)
        {
            throw new NotImplementedException();
        }

        public BLServerReference.Guest GetUsersGuestByEmail(string email, int userid)
        {
            return blClient.GetUsersGuestByEmail(email, userid, Hash);
        }

        public Task<BLServerReference.Guest> GetUsersGuestByEmailAsync(string email, int userid)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<BLServerReference.Guest> GetUsersGuests(BLServerReference.User user)
        {
            return blClient.GetUsersGuests(user, Hash);
        }

        public Task<BLServerReference.Guest[]> GetUsersGuestsAsync(BLServerReference.User user)
        {
            throw new NotImplementedException();
        }

        public ModelValidationReportOfGuestsJEn804l CreateGuest(BLServerReference.Guest guest)
        {
            return blClient.CreateGuest(guest, Hash);
        }

        public Task<BLServerReference.Guest> CreateGuestAsync(BLServerReference.Guest guest)
        {
            throw new NotImplementedException();
        }

        public BLServerReference.Guest GetGuestByID(int id)
        {
            return blClient.GetGuestByID(id, Hash);
        }

        public Task<BLServerReference.Guest> GetGuestByIDAsync(int id)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<BLServerReference.Invite> GetGuestsInvites(BLServerReference.Guest g)
        {
            return blClient.GetGuestsInvites(g, Hash);
        }

        public Task<BLServerReference.Invite[]> GetGuestsInvitesAsync(BLServerReference.Guest g)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<BLServerReference.Guest> SearchForGuests(string keyword, int userid)
        {
            return blClient.SearchForGuests(keyword, userid, Hash);
        }

        public Task<BLServerReference.Guest[]> SearchForGuestsAsync(string keyword, int userid)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<BLServerReference.Guest> SearchForNonInvitedGuests(string keyword, int eventID, int p)
        {
            return blClient.SearchForNonInvitedGuests(keyword, eventID, p, Hash);
        }

        public Task<BLServerReference.Guest[]> SearchForNonInvitedGuestsAsync(string keyword, int eventID, int p)
        {
            throw new NotImplementedException();
        }

        public void SendMail(MailMessage message)
        {
            blClient.SendMail(message.To.FirstOrDefault().Address, message.Body, message.Subject, Hash);
        }

        public Task SendMailAsync(string toAddress, string body, string subject)
        {
            throw new NotImplementedException();
        }

        public ModelValidationReportOfInvitesJEn804l CreateInvite(BLServerReference.Invite invite)
        {
            return blClient.CreateInvite(invite, Hash);
        }

        public Task<BLServerReference.Invite> CreateInviteAsync(BLServerReference.Invite invite)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<BLServerReference.Invite> GetInvitesByEvent(BLServerReference.Event ev)
        {
            return blClient.GetInvitesByEvent(ev, Hash);
        }

        public Task<BLServerReference.Invite[]> GetInvitesByEventAsync(BLServerReference.Event ev)
        {
            throw new NotImplementedException();
        }

        public BLServerReference.Invite GetInviteByEventAndGuest(BLServerReference.Event ev, BLServerReference.Guest guest)
        {
            return blClient.GetInviteByEventAndGuest(ev, guest, Hash);
        }

        public Task<BLServerReference.Invite> GetInviteByEventAndGuestAsync(BLServerReference.Event ev, BLServerReference.Guest guest)
        {
            throw new NotImplementedException();
        }

        public ModelValidationReportOfInvitesJEn804l UpdateInvite(BLServerReference.Invite invite)
        {
            return blClient.UpdateInvite(invite, Hash);
        }

        public Task<BLServerReference.Invite> UpdateInviteAsync(BLServerReference.Invite invite)
        {
            throw new NotImplementedException();
        }

        public BLServerReference.Invite GetInviteById(int id)
        {
            return blClient.GetInviteById(id, Hash);
        }

        public Task<BLServerReference.Invite> GetInviteByIdAsync(int id)
        {
            throw new NotImplementedException();
        }

        public BLServerReference.Invite GetInviteByHash(string hash, int guestID)
        {
            return blClient.GetInviteByHash(hash, guestID, Hash);
        }

        public Task<BLServerReference.Invite> GetInviteByHashAsync(string hash, int guestID)
        {
            throw new NotImplementedException();
        }


        public bool DeleteInvite(int eventID, int inviteID, int guestID)
        {
            return blClient.DeleteInvite(eventID, inviteID, guestID, Hash);
        }

        public void ResendActivationEmail(int userid)
        {
            blClient.ResendActivationEmail(userid, Hash);
        }


        public decimal GetAverageGuestGifts(Guest guest)
        {
            return blClient.GetAverageGuestGifts(guest, Hash);
        }


        public List<User> GetAllUsers()
        {
            return blClient.GetAllUsers(Hash).ToList();
        }


        public void DeleteUser(User user)
        {
            blClient.DeleteUser(user, Hash);
        }


        public ModelValidationReportOfUsersJEn804l UpdateUser(User user)
        {
            return blClient.UpdateUser(user, Hash);
        }
    }
}
